using Autofac;
using System.Reflection;
using Autofac.Extras.Quartz;
using SmartLink.Application.IServices;
using SmartLink.Application.Services;
using SmartLink.IRepository;
using SmartLink.Repository;
using SmartLink.Domain.IServices;
using SmartLink.Domain.Services;
using SmartLink.Domain.Entity;
using Quartz.Core;

namespace SmartLink.Job.App_Start
{
    internal class Bootstrapper
    {
        internal static IContainer InitializeContainer()
        {
            // 容器建立者
            var builder = new ContainerBuilder();

            //repository
            builder.RegisterType<SYS_UserRepo>().As<ISYS_UserRepo>();
            builder.RegisterType<SYS_UserLoadingRepo>().As<ISYS_UserLoadingRepo>();
            builder.RegisterType<SYS_MenuRepo>().As<ISYS_MenuRepo>();
            builder.RegisterType<PER_ActionPermissionsRepo>().As<IPER_ActionPermissionsRepo>();
            builder.RegisterType<BIZ_OrganizationRepo>().As<IBIZ_OrganizationRepo>();
            builder.RegisterType<BIZ_OrganizationDeptRepo>().As<IBIZ_OrganizationDeptRepo>();
            builder.RegisterType<SYS_AttachmentRepo>().As<ISYS_AttachmentRepo>();
            builder.RegisterType<BIZ_UserToOrganizationRepo>().As<IBIZ_UserToOrganizationRepo>();
            builder.RegisterType<PER_RoleGroupRepo>().As<IPER_RoleGroupRepo>();
            builder.RegisterType<PER_MenuPermissionsRoleRepo>().As<IPER_MenuPermissionsRoleRepo>();
            builder.RegisterType<PER_ActionPermissionsRoleRepo>().As<IPER_ActionPermissionsRoleRepo>();
            builder.RegisterType<PER_ActionPermissionsRepo>().As<IPER_ActionPermissionsRepo>();
            builder.RegisterType<PER_PermissionsGroupRepo>().As<IPER_PermissionsGroupRepo>();
            builder.RegisterType<PER_UserToRoleRepo>().As<IPER_UserToRoleRepo>();
            builder.RegisterType<PER_DataPermissionsRepo>().As<IPER_DataPermissionsRepo>();
            builder.RegisterType<SYS_DictionaryRepo>().As<ISYS_DictionaryRepo>();
            builder.RegisterType<SYS_UserLoadingRepo>().As<ISYS_UserLoadingRepo>();
            builder.RegisterType<SYS_ModuleRepo>().As<ISYS_ModuleRepo>();
            builder.RegisterType<SYS_ModuleFunctionRepo>().As<ISYS_ModuleFunctionRepo>();
            builder.RegisterType<PER_ActionAuthorizationRepo>().As<IPER_ActionAuthorizationRepo>();
            builder.RegisterType<PER_DataAuthorizationRepo>().As<IPER_DataAuthorizationRepo>();
   
            //app层
            builder.RegisterType<AccountAppServices>().As<IAccountAppServices>();
            builder.RegisterType<SysBasicAppServices>().As<ISysBasicAppServices>();
            builder.RegisterType<UserLoadingAppServices>().As<IUserLoadingAppServices>();
            builder.RegisterType<SysModuleAppServices>().As<ISysModuleAppServices>();
            builder.RegisterType<PermissionAppServices>().As<IPermissionAppServices>();
            builder.RegisterType<RoleAppServices>().As<IRoleAppServices>();
            builder.RegisterType<JobProcessHelperAppServices>().As<IJobProcessHelperAppServices>();

            //domain层
            builder.RegisterType<BIZ_OrganizationDepartmentServices>().As<IBIZ_OrganizationDepartmentServices>();
            builder.RegisterType<BIZ_OrganizationServices>().As<IBIZ_OrganizationServices>();
            builder.RegisterType<BIZ_UserToOrganizationServices>().As<IBIZ_UserToOrganizationServices>();
            builder.RegisterType<SYS_MenuServices>().As<ISYS_MenuServices>();
            builder.RegisterType<SYS_UserLoadingServices>().As<ISYS_UserLoadingServices>();
            builder.RegisterType<SYS_UserServices>().As<ISYS_UserServices>();
            builder.RegisterType<SysBasicServices>().As<ISysBasicServices>();
            builder.RegisterType<SysModuleServices>().As<ISysModuleServices>();
            builder.RegisterType<PermissionServices>().As<IPermissionServices>();
            builder.RegisterType<RoleServices>().As<IRoleServices>();
            builder.RegisterType<SysAttachmentServices>().As<ISysAttachmentServices>();
            
            //Register IScheduler
            builder.RegisterModule(new QuartzAutofacFactoryModule());
            //Register jobs
            builder.RegisterModule(new QuartzAutofacJobsModule(Assembly.GetExecutingAssembly()));

            // 建立容器
            return builder.Build();
        }
    }
}